<template>
  <el-container>
    <el-aside></el-aside>
    <el-container>
      <el-header
        ><div>
          <el-link type="primary" icon="el-icon-shopping-cart-full"
            >商城</el-link
          >
          <el-link type="primary" href="/register" icon="el-icon-edit-outline"
            >注册</el-link
          >
          <el-link type="primary" href="/" icon="el-icon-discount"
            >首页</el-link
          >
        </div></el-header
      >
      <el-main
        >欢迎登录数码之家
        <el-form
          :model="ruleForm"
          status-icon
          :rules="rules"
          ref="ruleForm"
          class="demo-ruleForm"
          label-width="80px"
          style="width: 500px; margin: 70px auto"
        >
          <el-form-item label="用户名" prop="name">
            <el-input
              v-model.number="ruleForm.name"
              placeholder="由4到16位(字母，数字，下划线组成)"
            ></el-input>
          </el-form-item>
          <el-form-item label="密码" prop="pass">
            <el-input
              type="password"
              v-model="ruleForm.pass"
              autocomplete="off"
              placeholder="以字母开头，长度在6~18之间，只能包含字母、数字和下划线"
            ></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="submitForm('ruleForm')"
              >提交</el-button
            >
            <el-button @click="resetForm('ruleForm')">重置</el-button>
          </el-form-item>
        </el-form>
      </el-main>
      <el-footer>欢迎来到数码之家</el-footer>
    </el-container>
  </el-container>
</template>

<script>
export default {
  data() {
    var checkAge = (rule, value, callback) => {
      if (value === '') {
        return callback(new Error('用户名不能为空'))
      }
      if (/^[a-zA-Z0-9_]{4,16}$/.test(value)) {
        callback()
      } else {
        return callback(new Error('用户名不能使用'))
      }
    }
    var validatePass = (rule, value, callback) => {
      if (value === '') {
        callback(new Error('请输入密码'))
      } else {
        if (/^[a-zA-Z]\w{5,17}$/.test(value)) {
          callback()
        } else {
          callback(new Error('密码不合法!'))
        }
        callback()
      }
    }
    return {
      ruleForm: {
        name: '',
        pass: '',
      },
      rules: {
        name: [{ validator: checkAge, trigger: 'blur' }],
        pass: [{ validator: validatePass, trigger: 'blur' }],
      },
    }
  },
}
</script>

<style lang="scss" scoped>
.el-header,
.el-footer {
  color: red;
  text-align: center;
  line-height: 40px;
}
.el-header > div > .el-link {
  padding-right: 20px;
  float: right;
  font-size: 15px;
}
.el-aside {
  background-image: url('https://cdn.web-global.fds.api.mi-img.com/mcfe--mi-account/static/static/media/banner.5b1efcd8.jpg');
  color: #333;
  text-align: center;
  background-size: 100% 100%;
  background-repeat: no-repeat;
  width: 375px;
}
.el-main {
  color: #191919;
  font-size: 30px;
  text-align: center;
  line-height: 100%;
  padding-top: 80px;
  padding-bottom: 80px;
  height: 1200px;
  > div {
    color: #191919;
    font-size: 15px;
    margin-top: 10px;
  }
}
</style>
